package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService;

    /**
     * 查询分类商标数据
     * @param pageNum
     * @param pageSize
     * @param categoryBrandDto
     * @return
     */
    @GetMapping("/getCategoryBrandPageList/{page}/{limit}")
    public Result getCategoryBrandPageList(@PathVariable("page") Integer pageNum,
                                           @PathVariable("limit") Integer pageSize ,CategoryBrandDto categoryBrandDto){

      PageInfo<CategoryBrand> pageInfo = categoryBrandService.getCategoryBrandPageList(pageNum,pageSize,categoryBrandDto);
      return Result.ok(pageInfo);
    }

    /**
     * 实现分类商标表添加功能
     * @param categoryBrand
     * @return
     */
    @PostMapping("/saveCategoryBrandById")
    public Result saveCategoryBrandById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.insertCategoryBrandById(categoryBrand);
        return Result.ok();
    }

    /**
     * 实现分类商标表修改功能
     * @param categoryBrand
     * @return
     */
    @PutMapping("/updateCategoryBrandById")
    public Result updateCategoryBrandById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateCategoryBrandById(categoryBrand);
        return Result.ok();
    }

    /**
     * 实现分类商标表删除功能
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCategoryBrandById/{id}")
    public Result deleteCategoryBrandById(@PathVariable("id") Long id){
        categoryBrandService.deleteCategoryBrandById(id);
        return Result.ok();
    }

    /**
     * 根据分类id查询商标
     * @param categoryId
     * @return
     */
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId(@PathVariable("categoryId") Long categoryId){
        List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.ok(brandList);
    }
}
